28 #ifndef _spoton_listener_h_
29 #define _spoton_listener_h_
33 #include <QSqlDatabase>
36 #if QT_VERSION >= 0x050300 && defined(SPOTON_WEBSOCKETS_ENABLED)
37 #include <QWebSocketServer>
39 #if QT_VERSION >= 0x050501 && defined(SPOTON_BLUETOOTH_ENABLED)
40 #include <qbluetoothserver.h>
41 #include <qbluetoothserviceinfo.h>
42 #include <qbluetoothsocket.h>
45 #include "spot-on-neighbor.h"
47 class QNetworkInterface;
66 void setMaxPendingConnections(
const int maxPendingConnections)
68 QTcpServer::setMaxPendingConnections(qMax(1, maxPendingConnections));
71 void incomingConnection(qintptr socketDescriptor);
77 void newConnection(
const qintptr socketDescriptor,
78 const QHostAddress &address,
91 m_maxPendingConnections = 5;
93 SIGNAL(readyRead(
void)),
95 SLOT(slotReadyRead(
void)));
102 bool clientExists(
const QHostAddress &address,
const quint16 port)
const
104 return m_clients.contains(QString(
"%1:%2:%3").
105 arg(address.toString()).
106 arg(address.scopeId()).
110 int maxPendingConnections(
void)
const
112 return m_maxPendingConnections;
115 void addClientAddress(
const QString &address)
117 m_clients.insert(address, 0);
120 void setMaxPendingConnections(
const int maxPendingConnections)
122 m_maxPendingConnections = qMax(1, maxPendingConnections);
126 QHash<QString, char> m_clients;
127 int m_maxPendingConnections;
131 void slotClientDestroyed(QObject *
object)
136 QString client(object->property(
"address").toString());
138 m_clients.remove(client);
141 void slotReadyRead(
void);
144 void newConnection(
const qintptr socketDescriptor,
145 const QHostAddress &address,
147 void newDatagram(
const QByteArray &datagram,
148 const QHostAddress &address,
152 #if QT_VERSION >= 0x050300 && defined(SPOTON_WEBSOCKETS_ENABLED)
153 class spoton_listener_websocket_server:
public QWebSocketServer
156 spoton_listener_websocket_server(
const QWebSocketServer::SslMode sslMode,
159 QWebSocketServer(QString::number(id), sslMode, parent)
164 ~spoton_listener_websocket_server()
168 void setMaxPendingConnections(
const int maxPendingConnections)
170 QWebSocketServer::setMaxPendingConnections(qMax(1, maxPendingConnections));
185 const QString &scopeId,
186 const int maximumClients,
188 const QString &echoMode,
189 const unsigned int keySize,
190 const QByteArray &certificate,
191 const QByteArray &privateKey,
192 const QByteArray &publicKey,
193 const bool useAccounts,
194 const qint64 maximumBufferSize,
195 const qint64 maximumContentLength,
196 const QString &transport,
197 const bool shareAddress,
198 const QString &orientation,
200 const QString &sslControlString,
202 const int passthrough,
203 const int sourceOfRandomness,
204 const QByteArray &privateApplicationCredentials,
205 const QString &socketOptions,
208 QHostAddress externalAddress(
void)
const;
209 QHostAddress localAddress(
void)
const;
210 QString orientation(
void)
const;
211 QString serverAddress(
void)
const;
212 QString transport(
void)
const;
213 bool isListening(
void)
const;
214 bool listen(
const QString &address,
const quint16 port);
215 quint16 externalPort(
void)
const;
216 quint16 serverPort(
void)
const;
218 void updateConnectionCount(
void);
221 #if QT_VERSION >= 0x050501 && defined(SPOTON_BLUETOOTH_ENABLED)
222 QBluetoothServiceInfo *m_bluetoothServiceInfo;
224 QByteArray m_certificate;
225 QByteArray m_privateApplicationCredentials;
226 QByteArray m_privateKey;
227 QByteArray m_publicKey;
228 QNetworkInterface *m_networkInterface;
229 #if QT_VERSION >= 0x050501 && defined(SPOTON_BLUETOOTH_ENABLED)
230 QPointer<QBluetoothServer> m_bluetoothServer;
232 QPointer<spoton_external_address> m_externalAddress;
233 QPointer<spoton_listener_tcp_server> m_tcpServer;
234 QPointer<spoton_listener_udp_server> m_udpServer;
235 #if QT_VERSION >= 0x050300 && defined(SPOTON_WEBSOCKETS_ENABLED)
236 QPointer<spoton_listener_websocket_server> m_webSocketServer;
238 QPointer<spoton_sctp_server> m_sctpServer;
242 QString m_orientation;
244 QString m_socketOptions;
245 QString m_sslControlString;
247 QTimer m_externalAddressDiscovererTimer;
252 int m_maximumClients;
254 int m_sourceOfRandomness;
256 qint64 m_maximumBufferSize;
257 qint64 m_maximumContentLength;
258 quint16 m_externalPort;
260 unsigned int m_keySize;
261 QString errorString(
void)
const;
262 int maxPendingConnections(
void)
const;
263 qint64 id(
void)
const;
264 void prepareNetworkInterface(
void);
265 void saveExternalAddress(
const QHostAddress &address,
266 const QSqlDatabase &db);
267 void saveStatus(
const QSqlDatabase &db);
270 void slotDiscoverExternalAddress(
void);
271 void slotExternalAddressDiscovered(
const QHostAddress &address);
272 void slotNeighborDisconnected(
void);
273 void slotNewConnection(
const qintptr socketDescriptor,
274 const QHostAddress &address,
276 #if QT_VERSION >= 0x050501 && defined(SPOTON_BLUETOOTH_ENABLED)
277 void slotNewConnection(
void);
279 #if QT_VERSION >= 0x050300 && defined(SPOTON_WEBSOCKETS_ENABLED)
280 void slotNewWebSocketConnection(
void);
282 void slotTimeout(
void);
285 void newNeighbor(
const QPointer<spoton_neighbor> &neighbor);